package org.grayrabbit.cms.publish.generate;

import java.util.Iterator;
import java.util.List;

import org.grayrabbit.cms.entity.Admin;
import org.grayrabbit.cms.publish.api.Generatable;
import org.grayrabbit.cms.publish.generate.factory.AbstractFactory;
import org.grayrabbit.cms.util.MD5;

import freemarker.template.Configuration;

public abstract class Mission implements Iterator<GenTask>{
	
	private int indexNum;
	private int catNum;
	private int surveryNum;
	private int topicNum;
	private int contentNum;
	private int assNum;
	private List<String> list;
	private Configuration config;
	private String modelType;
	private String genType;
	private Admin admin;
	protected Generatable generatable;
	public final static int MAX = 5;
	
	
	public String getModelType() {
		return modelType;
	}

	public void setModelType(String modelType) {
		this.modelType = modelType;
	}

	public String getGenType() {
		return genType;
	}

	public void setGenType(String genType) {
		this.genType = genType;
	}
	
	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public Configuration getConfig() {
		return config;
	}

	public void setConfig(Configuration config) {
		this.config = config;
	}

	public int getIndexNum() {
		return indexNum;
	}

	public void setIndexNum(int indexNum) {
		this.indexNum = indexNum;
	}

	public int getCatNum() {
		return catNum;
	}

	public void setCatNum(int catNum) {
		this.catNum = catNum;
	}

	public int getSurveryNum() {
		return surveryNum;
	}

	public void setSurveryNum(int surveryNum) {
		this.surveryNum = surveryNum;
	}

	public int getTopicNum() {
		return topicNum;
	}

	public void setTopicNum(int topicNum) {
		this.topicNum = topicNum;
	}

	public int getContentNum() {
		return contentNum;
	}

	public void setContentNum(int contentNum) {
		this.contentNum = contentNum;
	}

	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
	}
	
	public int getAssNum() {
		return assNum;
	}

	public void setAssNum(int assNum) {
		this.assNum = assNum;
	}

	public int getTotal(){
		return getAssNum()+getCatNum()+getContentNum()+getIndexNum()+getSurveryNum()+getTopicNum();
	}
	public abstract GenTask next();
	
	public int getFinished(){
		return  AbstractFactory.percent.get(getPercentKey()+AbstractFactory.FINISHED).intValue();
	}
	
	public String getPercentKey() {
		String ids="";
		for(String id:this.getList()){
			ids+=id+"_";
		}
		return MD5.getMD5Str(this.getGenType()+"_"+this.getModelType()+"_"+ids);
	}

	public void setGeneratable(Generatable generatable) {
		this.generatable = generatable;
	}
}